package cn.lxb.netstat.collector;

import java.time.Duration;

import javax.annotation.PostConstruct;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author TFB
 */
@Data
@Slf4j
@ConfigurationProperties(prefix = "netstat-collector")
public class NetstatCollectorProperties {
	Persist persist = new Persist();

	@PostConstruct
	public void init() {
		if (Type.FILE == persist.type && persist.file == null) {
			persist.file = new FileProps();
		}
		log.info("NetstatCollectorProperties:"+this);
	}

	@Data
	public static class Persist {
		@NotNull
		Type type = Type.MEMORY;
		FileProps file;
	}

	public static enum Type {
		FILE,MEMORY
	}

	public static enum Format {
		JSON, YAML
	}

	@Data
	public static class FileProps {
		@NotBlank
		String path = System.getProperty("user.home") + java.io.File.separator + "netstat-collector-data.txt";
		boolean loadOnStart = true;
		@NotNull
		Duration writePeriod = Duration.ofSeconds(60);
		@NotNull
		Duration writeDelay = Duration.ofSeconds(60);
		@NotNull
		Format format = Format.JSON;

	}

}
